<template>
  <div class="app-container">
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item>
        <el-select
            v-model="searchObj.school"
            placeholder="请选择学校"
        >
          <el-option
              v-for="item in schoolList"
              :key="item.id"
              :label="item.name"
              :value="item.id"/>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-select
            v-model="searchObj.department"
            placeholder="请选择学院"
            @change="departmentChanged">
          <el-option
              v-for="item in departmentList"
              :key="item.id"
              :label="item.name"
              :value="item.name"
          />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-input v-model="searchObj.username" placeholder="姓名"/>
      </el-form-item>
      <el-form-item>
        <el-input v-model="searchObj.address" placeholder="学号"/>
      </el-form-item>

      <el-button type="primary" icon="el-icon-search" @click="fetchUserInfo">查询</el-button>
      <el-button type="default" @click="resetData()">清空</el-button>

      <a style="left: 100px;width: 50%;height: 50%;padding-left: 0px;margin-left: 50px;text-decoration: underline" href="/api1/api/exportUnReported" target="_blank">导出未打卡</a>




    </el-form>

    <!-- banner列表 -->
    <el-table v-loading="listLoading" :data="list"
              border
              fit
              highlight-current-row>

      <el-table-column
          label="编号"
          width="60"
          align="center">
        <template slot-scope="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>

      <!--      <el-table-column label="姓名">-->
      <!--        <template slot-scope="scope">-->
      <!--          <img :src="'data:image/jpeg;base64,'+scope.row.logoData" width="80">-->
      <!--        </template>-->
      <!--      </el-table-column>-->

      <el-table-column prop="realName" label="姓名"width="90"/>
      <el-table-column prop="idNumber" label="身份证" />
      <el-table-column prop="university" label="学校"/>
      <el-table-column prop="department" label="学院"/>


      <el-table-column label="今日打卡状态" width="80">
        <template slot-scope="scope">
          {{ scope.row.reportStatus === 0 ? '未打卡' : '已打卡' }}
        </template>
      </el-table-column>
      <!--      <el-table-column prop="createTime" label="创建时间"/>-->
      <el-table-column label="操作" width="230" align="center">
        <template slot-scope="scope">

          <el-button type="primary" size="mini" @click="catDetails">详细内容</el-button>

          <!--          <router-link :to="'/hospSet/hospital/show/'+scope.row.id">
                      <el-button type="primary" size="mini">查看</el-button>
                    </router-link>
                    <router-link :to="'/hospSet/hospital/schedule/'+scope.row.hoscode">
                      <el-button type="primary" size="mini">排班</el-button>
                    </router-link>-->
          <el-button v-if="scope.row.locked == 1"  type="primary" size="mini" @click="updateStatus(scope.row.id, 1)">解锁</el-button>
          <el-button v-if="scope.row.locked == 0"  type="danger" size="mini" @click="updateStatus(scope.row.id, 0)">锁定</el-button>
        </template>

      </el-table-column>
    </el-table>

    <!-- 分页组件 -->
    <el-pagination
        :current-page="currentPage"
        :total="total"
        :page-size="limit"
        :page-sizes="[5, 10, 20, 30, 40, 50, 100]"
        style="padding: 30px 0; text-align: center;"
        layout="sizes, prev, pager, next, jumper, ->, total, slot"
        @current-change="fetchUserInfo"
        @size-change="changeSize"
    />
  </div>
</template>

<script>
import userManagerApi from "@/views/api/userManager";
import popMessage from "@/utils/popMessage";
import request from "@/utils/request";
export default {
  name:"HealthList",
  data() {
    return {
      listLoading: false, // 数据是否正在加载
      list: null, // 医院列表数据集合
      total: 0, // 数据库中的总记录数
      currentPage: 1, // 默认页码
      limit: 5, // 每页记录数
      searchObj: {
        school:'',
        department:'',
        username:'',
        address:'',
        reportStatus:'',
      }, // 查询表单对象
      schoolList: [{id:'10086',name:'东莞帝国理工学院'}], //所有学校集合
      departmentList: [],   //所有学院集合
      statusReport:false

    }
  },
  mounted() {

    this.fetchUserInfo()

  },
  created() {
    this.findAllDepartMent();

  },
  activated() {
    // this.findAllDepartMent()
  },
  methods: {


    exportData()
    {
      request({
        url: '/api1/api/exportUnReported',
        method: 'post',
        headers:'Content-Type: multipart/form-data',
      }).then(res=>{

        this.$router.push(this.$route.params.path)

      })
    },

    //查询用户信息
    fetchUserInfo(page=1) {
      this.currentPage = page
      console.log("dadsadasfgretrfhewhtrwegtrfhegrf")
      console.log(this.currentPage)

      let data={
        currentPage:1,
        username:this.searchObj.username,
        address:this.searchObj.address,
        reportStatus:this.searchObj.reportStatus,
        department: this.searchObj.department

      }
      userManagerApi.getUserInfo(null,data).then(res=>{

        console.log(res)


        this.list=res.data.data.userInfos;
        this.total=res.data.data.totalPage


      })
    },

    findAllDepartMent(){
      userManagerApi.getAllDepartMent(null,{name:"学院"}).then(res=>
      {

        console.log(res.data)
        this.departmentList=res.data.data
      }).catch(error=>
      {
        postMessage(false,"获取数据失败","error")
        /*postMessage(true,"获取数据失败","error")*/
        // console.log(error)
      })
    },

    departmentChanged() {
      //初始化值
      // popMessage(true,this.searchObj.department,"info")
    },

    updateStatus(id, status){



    },
    //分页，页码变化
    changeSize() {
      this.limit = size
      this.fetchUserInfo()
    },
    resetData(){
      this.searchObj.school='';
      this.searchObj.department="";
      this.searchObj.address="";
      this.searchObj.username="";
      this.searchObj.reportStatus="";
      this.currentPage=1;
      this.statusReport=false;

    },

    selectSR()
    {
      this.searchObj.reportStatus=this.statusReport==true?0:1;
    },
    catDetails()
    {

    },
    getUnReported()
    {
      userManagerApi.getUnReported().then(res=>{

        this.list=res.data.data;
        this.total=1

      }).catch(err=>{})
    }

  }
}
</script>

<style scoped>

</style>
